<template>
	<view>
		<custom-navbar title="参加活动学习记录"></custom-navbar>
		<view :style="'padding-bottom: 200rpx;padding-top:'+barHeight+'px'">
			<navigator :url="'/pages/activity/detail?id='+item.id" hover-class="none" class="list"
				v-for="(item,index) in list" :key="index">
				<view class="title">{{item.activity_title}}</view>
				<view class="item flex">
					<view>活动日期</view>
					<view>{{item.activity_time}}</view>
				</view>
				<view class="item flex">
					<view>活动地点</view>
					<view>{{item.activity_address}}</view>
				</view>
				<!-- <view class="item flex">
					<view>活动类型</view>
					<view>{{item.activity_type_text}}</view>
				</view> -->
			</navigator>
			<xw-empty :isShow="empty" text="暂无数据" textColor="#777777"></xw-empty>
			<view class="btom-btn">
				<view class="btn" @click="toUrl()">新增</view>
			</view>
		</view>
	</view>
</template>

<script>
	import CustomNavbar from '@/components/custom-navbar.vue';
	import {
		activityList
	} from '@/api/apiData.js';
	export default {
		data() {
			return {
				totalPage: 1,
				page: 0,
				offset: 10,
				list: [],
				scrollTop: 0,
				empty: false,
				loadText: {
					loadmore: '点击或上拉加载更多',
					loading: '努力加载中',
					nomore: '实在没有了'
				},
				status: 'loadmore',
				barHeight: '',
			};
		},
		onLoad() {

		},
		components: {
			CustomNavbar
		},
		created() {
			const systemInfo = uni.getSystemInfoSync();
			let statusBarHeight = systemInfo.statusBarHeight; // 获取状态栏高度
			let navBarHeight = ''
			if (systemInfo.platform === 'android') {
				navBarHeight = statusBarHeight + 48; // Android 导航栏高度
			} else {
				navBarHeight = statusBarHeight + 44; // iOS 导航栏高度
			}
			this.barHeight = navBarHeight
		},
		onPageScroll(e) {
			const that = this;
			that.scrollTop = e.scrollTop;
		},
		onReachBottom() {
			const that = this;
			that.getlist();
		},
		onShow() {
			this.status = 'nomore';
			this.scrollTop = 0;
			this.empty = false;
			this.totalPage = 1;
			this.page = 0;
			this.list = [];
			this.getlist();
		},
		methods: {
			async getlist() {
				const that = this;
				const {
					totalPage,
					page,
					offset,
					list,
				} = that;

				let obj = {
					size: offset,
					page: page + 1,
				};
				that.status = 'loading';
				if (totalPage > page) {
					let result = await activityList(obj);
					if (result.code == 1) {
						that.page = page + 1;
						if (result.data.total == 0) {
							that.empty = true;
							that.status = 'nomore';
							return;
						}
						that.empty = false;
						setTimeout(() => {
							that.status = 'loadmore';
						}, 500);
						that.list = list.concat(result.data.list);
						that.totalPage = Math.ceil(result.data.total / offset);
					}
				} else {
					setTimeout(() => {
						that.status = 'nomore';
					}, 500);
				}
			},
			toUrl() {
				uni.navigateTo({
					url: '/pages/activity/add'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.list {
		background: white;
		border-radius: 8rpx;
		padding: 15rpx 34rpx;
		margin: 16rpx 24rpx;

		.title {
			border-bottom: solid 1rpx #EBEBEB;
			font-size: 32rpx;
			padding-bottom: 16rpx;
		}

		.item {
			padding: 16rpx 0;
			font-size: 28rpx;
		}

		.item view:nth-child(1) {
			color: #C8C8C8;
			margin-right: 16rpx;
		}
	}

	.btom-btn {
		position: fixed;
		background: white;
		bottom: 0;
		left: 0;
		width: 100%;
	}

	.btn {
		background: #FF9008;
		border-radius: 32rpx;
		line-height: 72rpx;
		margin: 50rpx 40rpx;
		text-align: center;
		color: white;
	}
</style>